#------------------------------------------------------------------------------
# Figure 3
#==============================================================================
tess = import(here('data','processed',"tess_cleaned.dta"))
tess = subset(tess, year==2016)
tess <- tess[!is.na(tess$weight),]

t0 <- paste0("topic_",c("debate","election","football"))
t1 <- paste0("topic1_",c("genewilder","spacex","chrisbrown","earthquake","hurricane"))
t2 <- paste0("topic2_",c("shawtylo","genniferflowers","arnoldpalmer","bradpitt"))

pdf(here('results','figures',"topic_multiple_choice.pdf"),paper="special",height=8,width=9)
layout(matrix(1:4,2,2,byrow=TRUE))
par(mar=c(5,10,4,1))
topic1.name <- c("Presidential Debate","Presidential Election", "Football",
	"Gene Wilder","SpaceX","Chris Brown","Earthquake","Hurricane")
a1<-colMeans(tess[tess$k_event==0&tess$k_imp==1,c(t0,t1)],na.rm=TRUE)
topic1.name <- topic1.name[order(a1)]
a1 <- a1[order(a1)]

topic2.name <- c("Presidential Debate","Presidential Election", "Football",
	"Shatw Lo","Gennifer Flowers","Arnold Palmer","Bradpitt/Angelina Jolie")
b1<-colMeans(tess[tess$k_event==1&tess$k_imp==1,c(t0,t2)],na.rm=TRUE)

topic2.name <- topic2.name[order(b1)]
b1 <- b1[order(b1)]

loc <- barplot(a1,beside=TRUE,horiz=TRUE,col=c(rep("gray",6),"pink","red"),axisname=FALSE,
	xlim=c(0,1),main="Important Matters | Before Debate")
axis(2,loc,topic1.name,las=1)
abline(v=c(0.1,0.2,0.5,0.8),col="black",lwd=1,lty=2)

loc <- barplot(b1,beside=TRUE,horiz=TRUE,col=c(rep("gray",5),"pink","red"),axisname=FALSE,
	xlim=c(0,1),main="Important Matters | After Debate")
axis(2,loc,topic2.name,las=1)
abline(v=c(0.1,0.2,0.5,0.8),col="black",lwd=1,lty=2)

topic1.name <- c("Presidential Debate","Presidential Election", "Football",
	"Gene Wilder","SpaceX","Chris Brown","Earthquake","Hurricane")
a1<-colMeans(tess[tess$k_event==0&tess$k_imp==0,c(t0,t1)],na.rm=TRUE)
topic1.name <- topic1.name[order(a1)]
a1 <- a1[order(a1)]

topic2.name <- c("Presidential Debate","Presidential Election", "Football",
	"Shatw Lo","Gennifer Flowers","Arnold Palmer","Bradpitt/Angelina Jolie")
b1<-colMeans(tess[tess$k_event==1&tess$k_imp==0,c(t0,t2)],na.rm=TRUE)

topic2.name <- topic2.name[order(b1)]
b1 <- b1[order(b1)]

loc <- barplot(a1,beside=TRUE,horiz=TRUE,col=c(rep("gray",6),"pink","red"),axisname=FALSE,
	xlim=c(0,1),main="Political Matters | Before Debate")
axis(2,loc,topic1.name,las=1)
abline(v=c(0.1,0.2,0.5,0.8),col="black",lwd=1,lty=2)

loc <- barplot(b1,beside=TRUE,horiz=TRUE,col=c(rep("gray",5),"pink","red"),axisname=FALSE,
	xlim=c(0,1),main="Political Matters | After Debate")
axis(2,loc,topic2.name,las=1)
abline(v=c(0.1,0.2,0.5,0.8),col="black",lwd=1,lty=2)

dev.off()
